import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';


class _MyCupertinoLocalizationsDelegate extends LocalizationsDelegate<CupertinoLocalizations> {
  const _MyCupertinoLocalizationsDelegate();

  @override
  bool isSupported(Locale locale) => locale.languageCode == 'zh' || locale.languageCode == 'en';

  @override
  Future<CupertinoLocalizations> load(Locale locale) => MyCupertinoLocalizations.load(locale);

  @override
  bool shouldReload(LocalizationsDelegate<CupertinoLocalizations> old) => false;

  @override
  String toString() => 'DefaultCupertinoLocalizations.delegate(zh_CN)';
}

class MyCupertinoLocalizations implements CupertinoLocalizations {
  const MyCupertinoLocalizations();

  static const List<String> _shortWeekdays = <String>[
    '星期一',
    '星期二',
    '星期三',
    '星期四',
    '星期五',
    '星期六',
    '星期日',
  ];

  static const List<String> _shortMonths = <String>[
    '一月',
    '二月',
    '三月',
    '四月',
    '五月',
    '六月',
    '七月',
    '八月',
    '九月',
    '十月',
    '十一月',
    '十二月',
  ];

  static const List<String> _months = <String>[
    '一月',
    '二月',
    '三月',
    '四月',
    '五月',
    '六月',
    '七月',
    '八月',
    '九月',
    '十月',
    '十一月',
    '十二月',
  ];



  @override
  String datePickerYear(int yearIndex) => yearIndex.toString();

  @override
  String datePickerMonth(int monthIndex) => _months[monthIndex - 1];

  // @override
  // String datePickerDayOfMonth(int dayIndex) => dayIndex.toString();
  @override
  String datePickerDayOfMonth(int dayIndex, [int? weekDay]) => '$dayIndex/$weekDay';

  @override
  String datePickerHour(int hour) => hour.toString();

  @override
  String datePickerHourSemanticsLabel(int hour) => hour.toString() + " o'clock";

  @override
  String datePickerMinute(int minute) => minute.toString().padLeft(2, '0');

  @override
  String datePickerMinuteSemanticsLabel(int minute) {
    if (minute == 1)
      return '1 minute';
    return minute.toString() + ' minutes';
  }

  @override
  String datePickerMediumDate(DateTime date) {
    return '${_shortWeekdays[date.weekday - DateTime.monday]} '
        '${_shortMonths[date.month - DateTime.january]} '
        '${date.day.toString().padRight(2)}';
  }

  @override
  DatePickerDateOrder get datePickerDateOrder => DatePickerDateOrder.mdy;

  @override
  DatePickerDateTimeOrder get datePickerDateTimeOrder => DatePickerDateTimeOrder.date_time_dayPeriod;

  @override
  String get anteMeridiemAbbreviation => '上午';

  @override
  String get postMeridiemAbbreviation => '下午';

  @override
  String get alertDialogLabel => '提示';

  @override
  String timerPickerHour(int hour) => hour.toString();

  @override
  String timerPickerMinute(int minute) => minute.toString();

  @override
  String timerPickerSecond(int second) => second.toString();

  @override
  String timerPickerHourLabel(int hour) => '时';

  @override
  String timerPickerMinuteLabel(int minute) => '分';

  @override
  String timerPickerSecondLabel(int second) => '秒';

  @override
  String get cutButtonLabel => '剪切';

  @override
  String get copyButtonLabel => '复制';

  @override
  String get pasteButtonLabel => '黏贴';

  @override
  String get selectAllButtonLabel => '全选';

  /// Creates an object that provides US English resource values for the
  /// cupertino library widgets.
  ///
  /// The [locale] parameter is ignored.
  ///
  /// This method is typically used to create a [LocalizationsDelegate].
  static Future<CupertinoLocalizations> load(Locale locale) {
    if (locale.languageCode == 'zh') {
      return SynchronousFuture<CupertinoLocalizations>(const MyCupertinoLocalizations());
    }else {
      return SynchronousFuture<CupertinoLocalizations>(const DefaultCupertinoLocalizations());
    }
  }

  /// A [LocalizationsDelegate] that uses [DefaultCupertinoLocalizations.load]
  /// to create an instance of this class.
  static const LocalizationsDelegate<CupertinoLocalizations> delegate = _MyCupertinoLocalizationsDelegate();

  @override
  String get todayLabel => '今天';

  @override
  String get modalBarrierDismissLabel => '解散';

  @override
  String tabSemanticsLabel({int tabIndex = 1, int tabCount = 1}) {
    assert(tabIndex >= 1);
    assert(tabCount >= 1);
//    return 'Tab $tabIndex of $tabCount';
  return'当前页 $tabIndex/$tabCount';
  }

  @override
  // TODO: implement searchTextFieldPlaceholderLabel
  String get searchTextFieldPlaceholderLabel => '搜索';

  @override
  // TODO: implement timerPickerHourLabels
  List<String> get timerPickerHourLabels => const <String>['时', '小时'];

  @override
  // TODO: implement timerPickerMinuteLabels
  List<String> get timerPickerMinuteLabels => const <String>['min.'];

  @override
  // TODO: implement timerPickerSecondLabels
  List<String> get timerPickerSecondLabels => const <String>['sec.'];

  @override
  // TODO: implement noSpellCheckReplacementsLabel
  String get noSpellCheckReplacementsLabel => 'noSpellCheckReplacementsLabel';

  @override
  // TODO: implement backButtonLabel
  String get backButtonLabel => '返回';

  @override
  // TODO: implement cancelButtonLabel
  String get cancelButtonLabel => '取消';

  @override
  // TODO: implement clearButtonLabel
  String get clearButtonLabel => '清除';

  @override
  String datePickerStandaloneMonth(int monthIndex) {
    return _months[monthIndex - 1];
  }

  @override
  // TODO: implement lookUpButtonLabel
  String get lookUpButtonLabel => '查看';

  @override
  // TODO: implement menuDismissLabel
  String get menuDismissLabel => '消失';

  @override
  // TODO: implement searchWebButtonLabel
  String get searchWebButtonLabel => '查询';

  @override
  // TODO: implement shareButtonLabel
  String get shareButtonLabel => '分享';
}
